<?php
class AdAction extends BaseAction{
	
	  
    public function adList(){
    	$ad = M('Ad')->findAll();
    	$this->assign("list",$ad);
    	$this->display();
    }
    
    public function add(){
    	
    	$this->display();
    }
    
    public function doAdd(){
    	
    	$adObj = D('Ad');
    	$ad = $adObj->where('code="'.$_POST['code'].'"')->find();
    	
    	if($ad){
    		$this->error('广告标识已经存在！');
    	}else{
    		if($adObj->create()){
    			 if($adObj->add()){
    			 		$this->assign("jumpUrl","__URL__/adList");
    			 	  $this->success('广告添加成功！');
    			 }else{
    			 		$this->error('广告添加失败！');
    			 } 
    		}else{
    			$this->error($adObj->getError());
    		}
    		
     }
   }
   
   public function edit(){
   	  $ad = M('Ad')->where('id='.$_GET['aid'])->find();
   	  $this->assign("ad",$ad);
   	  $this->display();
   }
   
   public function doEdit(){
   	  $adObj = D('Ad');
   	  if($adObj->create()){
   	  	if($adObj->save()){
   	  		$this->assign("jumpUrl","__URL__/adList");
   	  		$this->success('广告修改成功！');
   	  	}else{
   	  		$this->error('没用进行任何修改操作！');
   	  	}
   	  }else{
   	  	$this->error($adObj->getError());
   	  }
   	  
   }
   
   public function del(){
   	  $adObj = M('Ad');
   	  $ad = $adObj->find($_GET['id']);
   	  if($ad){
   	  	if($ad['status']){
   	  		$adx = M('Ad')->where('id='.$_GET['id'])->delete();
   	  	}else{
   	  		$this->error('该广告是默认广告不能删除！');
   	  	}
   	  }else{
   	  	
   	  	$this->error('您要删除的广告不存在！');
   	  }
   		
   		if($adx){
   			$this->success('删除广告成功！');
   		}else{
   			$this->error('删除广告失败！');
   		}
   }
    
 
}
?>